package com.iocup.keybastion.authorize;

import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * @Description: 权限节点信息
 * @Author: xyjxust
 * @Date: 2021/11/26 14:08
 */
@Setter
@Getter
public class AuthorizeElement implements Serializable {
    /**
     * 权限码
     */
    private String code;

    /**
     * 权限类型
     */
    private String type;
    /**
     * url
     */
    private String url;
    /**
     * 可能的其他信息
     */
    private Map<String, Object> other = new HashMap<>();

    public static AuthorizeElement build() {
        return new AuthorizeElement();
    }

    public AuthorizeElement code(String code) {
        this.code = code;
        return this;
    }

    public AuthorizeElement type(String type) {
        this.type = type;
        return this;
    }

    public AuthorizeElement url(String url) {
        this.url = url;
        return this;
    }

    public AuthorizeElement putOther(String key, Object value) {
        this.other.put(key, value);
        return this;
    }

    public <T> T getOther(String key) {
        return other.containsKey(key) ? (T) other.get(key) : null;
    }
}
